package main

import (
	"fmt"
	"math/rand"
	"time"
)

// 1、打印九九乘法表。如果可以要求间隔均匀。
// 正序打印-左下角
func main1() {
	for i := 1; i <= 9; i++ {
		for j := 1; j <= i; j++ {
			fmt.Printf("%d*%d=%d\t", j, i, i*j)
			time.Sleep(1 * time.Second)
		}
		fmt.Println()
		time.Sleep(1 * time.Second)
	}
}

// 2、随机生成20以内的20个非0正整数，打印出来。
// 对生成的数值，第单数个（不是索引）累加求和，第偶数个累乘求积。打印结果
func main2() {
	src := rand.New(rand.NewSource(time.Now().UnixNano()))
	r20 := rand.New(src)
	odd_result := 0
	even_result := 1
	for i := 1; i <= 20; i++ {
		num := r20.Intn(19) + 1
		fmt.Printf("the %d random int, rand_num is:%d\n", i, num)
		if num%2 == 0 {
			even_result = even_result * num
			fmt.Printf("even_loop is:%d\n", even_result)
		} else {
			odd_result = odd_result + num
			fmt.Printf("odd_loop is:%d\n", odd_result)
		}
		time.Sleep(1 * time.Second)
	}
	fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
	fmt.Printf("All_odd_result is:(%d)\n", odd_result)
	fmt.Printf("All_even_result is:(%d)\n", even_result)
}

// 3、打印100以内的斐波那契数列
// 函数递归形式实现
func fibonaci(n int) (res int) {
	if n <= 1 {
		res = 1
	} else {
		res = fibonaci(n-1) + fibonaci(n-2)
	}
	return res
}

func main3() {
	result := 0
	for i := 0; i <= 20; i++ {
		result = fibonaci(i)
		if result > 100 {
			break
		} else {
			fmt.Printf("fabonaci(%d) of the result is: %d\n", i, result)
			time.Sleep(1 * time.Second)
		}
	}

}

func main() {
	fmt.Println("-------------第1题-----------------------")
	main1()
	fmt.Println("-------------第2题-----------------------")
	main2()
	fmt.Println("-------------第3题-----------------------")
	main3()
}
